<template>
  <div>
  </div>
</template>
<script lang="ts" setup>
import _ from "lodash";
import { inject, reactive, onMounted, onBeforeUnmount } from "vue";
import { useRouter, useRoute } from "vue-router";
import { timeFormat } from "@/utils/common";
import { useIntervalFn } from "@vueuse/core";

const realTime = inject("realTime") as any;
const itemObject = inject("itemObject") as any;
const cabinet = inject("cabinet") as any;
const route = useRoute();
const router = useRouter();

const state: {
  time: string;
  filedsOne: any;
  filedsTwo: any;
  filedsThree: any;
  filedsFourth: any;
  filedsFive: any;
  filedsSix: any;
  filedsSeven: any;
  controlOne: any;
  controlTwo: any;
  controlThree: any;
  emergencyPhone: string;
} = reactive({
  time: "",
  filedsOne: ["t1", "h1", "q1", "p3"],
  filedsTwo: ["t2", "p1"],
  filedsThree: ["t3", "p2"],
  filedsFourth: ["fp1", "fp2"],
  filedsFive: ["wt3"],
  filedsSix: ["wt4"],
  filedsSeven: ["wh1", "wq1", "wfp1", "wfp2"],
  controlOne: ["e1", "e2", "e3", "w1"],
  controlTwo: ["fp1", "fp2", "wfp1", "wfp2"],
  controlThree: ["wf1"],
  emergencyPhone: "",
});

interface Props {
  modelValue: any;
}
const props = withDefaults(defineProps<Props>(), {
  modelValue: {},
});

const getrightObj = (filed: String, property: any) => {
  let value = _.filter(itemObject.fullData, { mqttFiled: filed });
  if (props.modelValue.type) {
    return value[0][property];
  } else {
    return value[0]["objectNameVertical"];
  }
};

//循环泵切换
const control = (Filed: string) => {
  console.log("循环泵切换", Filed);
  switch (Filed) {
    case "fp1":
      //待控制fp1c
      break;
    case "fp2":
      //待控制fp2c
      break;
    default:
      break;
  }
};

const controlThree = (Filed: string) => {
  console.log("外循环风扇", Filed);
  switch (Filed) {
    case "wf1":
      //待控制wf1c
      break;

    default:
      break;
  }
};

//获取机柜详情
const getInfo = () => {
  cabinet.getInfoById(route.query).then((res: any) => {
    state.emergencyPhone = res.emergencyPhone;
  });
};

//计时
const initTime = () => {
  state.time = timeFormat("", "yyyy-mm-dd hh:MM:ss");
};
const { pause, resume, isActive } = useIntervalFn(
  () => {
    initTime();
  },
  1000,
  {
    immediate: true,
  }
);

onMounted(() => {
  //获取机柜详情
  getInfo();
  console.log("实时数据", route);
});

onBeforeUnmount(() => {
  pause();
});
</script>
<style lang="scss" scoped>

</style>
